using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;

namespace AfterEdge.Web.UI
{
    public class ClientEvent
    {
        private String _eventHandler;

        public ClientEvent() { }
        public ClientEvent(String eventHandler)
        {
            this._eventHandler = eventHandler;
        }

        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public String EventHandler
        {
            get { return this._eventHandler; }
            set { this._eventHandler = value; }
        }
    }
    
    public abstract class ClientEvents
    {
        private System.Web.UI.AttributeCollection _handlers;

        internal System.Web.UI.AttributeCollection Handlers
        {
            get
            {
                if (this._handlers == null)
                {
                    StateBag bag = new StateBag(true);
                    this._handlers = new System.Web.UI.AttributeCollection(bag);
                }

                return this._handlers;
            }
            set { this._handlers = value; }
        }

        protected ClientEvent GetValue(String key)
        {
            String eventHandler = this.Handlers[key];
            return ((eventHandler == null) ? null : new ClientEvent(eventHandler));
        }

        protected void SetValue(String key, ClientEvent value)
        {
            if (value != null)
                this.Handlers[key] = value.EventHandler;
            else
                this.Handlers.Remove(key);
        }
    }
}
